package com.csun.nusing.ui.activity;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.csun.nusing.R;
import com.csun.nusing.bean.UrlBean;
import com.csun.nusing.bean.jsonbean.DeviceSleepDataJsonBean;
import com.csun.nusing.bean.jsonbean.DeviceSleepDataJsonBean.DeviceSleepDataDataBean;
import com.csun.nusing.bean.jsonbean.DeviceSleepDataJsonBean.DeviceSleepDataDataBean.ListBean;
import com.csun.nusing.bean.jsonbean.FollowDeviceSearchBloodOxyJsonBean;
import com.csun.nusing.bean.jsonbean.FollowDeviceSearchBloodOxyJsonBean.DeviceSearchBloodOxyDataBean;
import com.csun.nusing.bean.jsonbean.FollowDeviceSearchBloodOxyJsonBean.DeviceSearchBloodOxyDataBean.BoxvygenListBean;
import com.csun.nusing.bean.jsonbean.FollowDeviceSearchBloodPressJsonBean;
import com.csun.nusing.bean.jsonbean.FollowDeviceSearchBloodPressJsonBean.FollowDeviceSearchBloodPressDataBean;
import com.csun.nusing.bean.jsonbean.FollowDeviceSearchBloodPressJsonBean.FollowDeviceSearchBloodPressDataBean.BpressureListBean;
import com.csun.nusing.bean.jsonbean.FollowDeviceSearchEcgJsonBean;
import com.csun.nusing.bean.jsonbean.FollowDeviceSearchEcgJsonBean.FollowDeviceSearchEcgDataBean;
import com.csun.nusing.bean.jsonbean.FollowDeviceSearchHeartRateJsonBean;
import com.csun.nusing.bean.jsonbean.FollowDeviceSearchHeartRateJsonBean.FollowDeviceSearchHeartRateDataBean;
import com.csun.nusing.bean.jsonbean.FollowDeviceSearchHeartRateJsonBean.FollowDeviceSearchHeartRateDataBean.HeartrateListBean;
import com.csun.nusing.bean.jsonbean.FollowDeviceSearchTemperatureJsonBean;
import com.csun.nusing.bean.jsonbean.FollowDeviceSearchTemperatureJsonBean.FollowDeviceSearchTemperatureDataBean;
import com.csun.nusing.bean.jsonbean.FollowDeviceSearchTemperatureJsonBean.FollowDeviceSearchTemperatureDataBean.TemperatureListBean;
import com.csun.nusing.presenter.HealthListPresenter;
import com.csun.nusing.ui.BaseActivity;
import com.csun.nusing.util.SPUtils;
import com.csun.nusing.util.ToastUtil;
import com.google.gson.Gson;
import com.home.administrator.okhttplibrary.IOkTaskCallback;
import com.home.administrator.okhttplibrary.OkHttpTask;
import com.home.administrator.okhttplibrary.OkHttpTask.OkHttpTaskBuidler.OkType;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lecho.lib.hellocharts.formatter.LineChartValueFormatter;
import lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter;
import lecho.lib.hellocharts.gesture.ZoomType;
import lecho.lib.hellocharts.model.Axis;
import lecho.lib.hellocharts.model.AxisValue;
import lecho.lib.hellocharts.model.Line;
import lecho.lib.hellocharts.model.LineChartData;
import lecho.lib.hellocharts.model.PointValue;
import lecho.lib.hellocharts.model.ValueShape;
import lecho.lib.hellocharts.model.Viewport;
import lecho.lib.hellocharts.view.LineChartView;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * 健康数据界面 ClassName: HealthListPresenter
 * 
 * @Description: TODO
 * @author fzq
 * @date 2017-11-2
 */
public class HealthListActivity extends BaseActivity<HealthListPresenter> {

	private ImageView xueyaiv;
	private ImageView xuetangiv;
	private ImageView wenduiv;
	private ImageView xintiaoiv;
	private ImageView xinlviv;
	private ImageView xindianiv;
	private ImageView huxiiv;
	private ImageView xueyangiv;
	private TextView starttimetv;
	private TextView endtimetv;
	private LinearLayout xueyall;
	private LinearLayout xuetangll;
	private LinearLayout temperaturell;
	private LinearLayout xintiaoll;
	private LinearLayout xinlvll;
	private LinearLayout xindianll;
	private LinearLayout huxill;
	private LinearLayout xueyangll;
	private LineChartView xueyalinechartview;
	private TextView xueyamintv;
	private TextView xueyamaxtv;
	private LineChartView xuetanglinechartview;
	private TextView xuetangmintv;
	private TextView xuetangmaxtv;
	private LineChartView wendulinechartview;
	private TextView wendumintv;
	private TextView wendumaxtv;
	private LineChartView xintiaolinechartview;
	private TextView xintiaomintv;
	private TextView xintiaomaxtv;
	private LineChartView xinlvlinechartview;
	private TextView xinlvmintv;
	private TextView xinlvmaxtv;
	private LineChartView xindianlinechartview;
	private TextView xindianmintv;
	private TextView xindianmaxtv;
	private LineChartView huxilinechartview;
	private TextView huximintv;
	private TextView huximaxtv;
	private LineChartView xueyanglinechartview;
	private TextView xueyangmintv;
	private TextView xueyangmaxtv;

	private int checkPosition = 0;// 默认选中第一个
	private List<LinearLayout> linelist;
	private List<ImageView> imagelist;
	private Calendar calendar;
	private int startyear;
	private int startmonth;
	private int startday;
	protected String startdaytime;
	private String enddaytime;
	private int endyear;
	private int endmonth;
	private int endday;
	private String olderId;
	private String authorization;
	// 转换格式
	private SimpleDateFormat sdf;
	private Date date;

	protected FollowDeviceSearchBloodPressJsonBean searchBloodPressJsonBean;
	private List<BpressureListBean> xueyadatalist;
	// 血压数据
	private List<String> xueyaXdate = new ArrayList<String>();
	private List<Integer> xueyascore = new ArrayList<Integer>();
	private List<Integer> xueyascore2 = new ArrayList<Integer>();
	private ArrayList<PointValue> xueyamPointValues;
	private ArrayList<PointValue> xueyamPoint2Values;
	private ArrayList<AxisValue> xueyamAxisXValues;
	private Line xueyaline;
	private ArrayList<Line> xueyalines;
	private LineChartData xueyadata;
	private Axis xueyaaxisX;
	private Axis xueyaaxisY;
	private Line xueyaline2;
	private LineChartData xueyadata2;
	protected FollowDeviceSearchTemperatureJsonBean temperatureJsonBean;
	private ArrayList<String> wenduXdate;
	private ArrayList<Float> wenduscore;
	private ArrayList<PointValue> wendumPointValues;
	private ArrayList<AxisValue> wendumAxisXValues;
	private List<TemperatureListBean> wendudatalist;
	protected FollowDeviceSearchHeartRateJsonBean heartrateJsonBean;
	private ArrayList<String> xinlvXdate;
	private ArrayList<Integer> xinlvscore;
	private ArrayList<PointValue> xinlvmPointValues;
	private ArrayList<AxisValue> xinlvmAxisXValues;
	private List<HeartrateListBean> xinlvdatalist;
	protected FollowDeviceSearchBloodOxyJsonBean devicesearchbloodoxyJsonBean;
	private List<BoxvygenListBean> xueyangdatalist;
	private ArrayList<String> xueyangXdate;
	private ArrayList<Float> xueyangscore;
	private ArrayList<PointValue> xueyangmPointValues;
	private ArrayList<AxisValue> xueyangmAxisXValues;
	protected FollowDeviceSearchEcgJsonBean ecgdataJsonBean;
	private ArrayList<String> xindianXdate;
	private ArrayList<Integer> xindianscore;
	private ArrayList<PointValue> xindianmPointValues;
	private ArrayList<AxisValue> xindianmAxisXValues;
	private String[] xindiandatalist;// 心电数据
	private OkHttpClient client;
	private DeviceSleepDataDataBean thisdata;
	private ArrayList<Integer> xintiaoscore;
	private ArrayList<String> xintiaoXdate;
	private ArrayList<PointValue> xintiaoPointValues;
	private ArrayList<AxisValue> xintiaomAxisXValues;
	private ArrayList<String> huxiXdate;
	private ArrayList<Integer> huxiscore;
	private ArrayList<PointValue> huxiPointValues;
	private ArrayList<AxisValue> huximAxisXValues;
	public static final MediaType JSON = MediaType
			.parse("application/json; charset=utf-8");

	@Override
	public int getContentViewId() {
		return R.layout.activity_nursing_health;
	}

	@Override
	public void initSubViews(View view) {
		super.initSubViews(view);
		initView();
	}

	/**
	 * 初始控件
	 * 
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	private void initView() {
		starttimetv = findViewById(R.id.nursing_health_starttime_tv);
		endtimetv = findViewById(R.id.nursing_health_endtime_tv);

		xueyall = findViewById(R.id.nursing_health_xueya_ll);
		xuetangll = findViewById(R.id.nursing_health_xuetang_ll);
		temperaturell = findViewById(R.id.nursing_health_temperature_ll);
		xintiaoll = findViewById(R.id.nursing_health_xintiao_ll);
		xinlvll = findViewById(R.id.nursing_health_xinlv_ll);
		xindianll = findViewById(R.id.nursing_health_xindian_ll);
		huxill = findViewById(R.id.nursing_health_huxi_ll);
		xueyangll = findViewById(R.id.nursing_health_xueyang_ll);

		linelist = new ArrayList<LinearLayout>();
		linelist.add(xueyall);
		linelist.add(xuetangll);
		linelist.add(temperaturell);
		linelist.add(xintiaoll);
		linelist.add(xinlvll);
		linelist.add(xindianll);
		linelist.add(huxill);
		linelist.add(xueyangll);

		xueyalinechartview = findViewById(R.id.nursing_health_xueya_linechartview);
		xueyamintv = findViewById(R.id.nursing_health_xueya_min_tv);
		xueyamaxtv = findViewById(R.id.nursing_health_xueya_max_tv);

		xuetanglinechartview = findViewById(R.id.nursing_health_xuetang_linechartview);
		xuetangmintv = findViewById(R.id.nursing_health_xuetang_min_tv);
		xuetangmaxtv = findViewById(R.id.nursing_health_xuetang_max_tv);

		wendulinechartview = findViewById(R.id.nursing_health_temperature_linechartview);
		wendumintv = findViewById(R.id.nursing_health_wendu_min_tv);
		wendumaxtv = findViewById(R.id.nursing_health_wendu_max_tv);

		xintiaolinechartview = findViewById(R.id.nursing_health_xintiao_linechartview);
		xintiaomintv = findViewById(R.id.nursing_health_xintiao_min_tv);
		xintiaomaxtv = findViewById(R.id.nursing_health_xintiao_max_tv);

		xinlvlinechartview = findViewById(R.id.nursing_health_xinlv_linechartview);
		xinlvmintv = findViewById(R.id.nursing_health_xinlv_min_tv);
		xinlvmaxtv = findViewById(R.id.nursing_health_xinlv_max_tv);

		xindianlinechartview = findViewById(R.id.nursing_health_xindian_linechartview);
		xindianmintv = findViewById(R.id.nursing_health_xindian_min_tv);
		xindianmaxtv = findViewById(R.id.nursing_health_xindian_max_tv);

		huxilinechartview = findViewById(R.id.nursing_health_huxi_linechartview);
		huximintv = findViewById(R.id.nursing_health_huxi_min_tv);
		huximaxtv = findViewById(R.id.nursing_health_huxi_max_tv);

		xueyanglinechartview = findViewById(R.id.nursing_health_xueyang_linechartview);
		xueyangmintv = findViewById(R.id.nursing_health_xueyang_min_tv);
		xueyangmaxtv = findViewById(R.id.nursing_health_xueyang_max_tv);

		xueyaiv = findViewById(R.id.nursing_health_icon_xueya_iv);
		xuetangiv = findViewById(R.id.nursing_health_icon_xuetang_iv);
		wenduiv = findViewById(R.id.nursing_health_icon_wendu_iv);
		xintiaoiv = findViewById(R.id.nursing_health_icon_xintiao_iv);
		xinlviv = findViewById(R.id.nursing_health_icon_xinlv_iv);
		xindianiv = findViewById(R.id.nursing_health_icon_xindian_iv);
		huxiiv = findViewById(R.id.nursing_health_icon_huxi_iv);
		xueyangiv = findViewById(R.id.nursing_health_icon_xueyang_iv);
		imagelist = new ArrayList<ImageView>();
		imagelist.add(xueyaiv);
		imagelist.add(xuetangiv);
		imagelist.add(wenduiv);
		imagelist.add(xintiaoiv);
		imagelist.add(xinlviv);
		imagelist.add(xindianiv);
		imagelist.add(huxiiv);
		imagelist.add(xueyangiv);

		xueyaiv.setOnClickListener(new click());
		xuetangiv.setOnClickListener(new click());
		wenduiv.setOnClickListener(new click());
		xintiaoiv.setOnClickListener(new click());
		xinlviv.setOnClickListener(new click());
		xindianiv.setOnClickListener(new click());
		huxiiv.setOnClickListener(new click());
		xueyangiv.setOnClickListener(new click());
		starttimetv.setOnClickListener(new click());
		endtimetv.setOnClickListener(new click());

	}

	@Override
	public void initData() {
		super.initData();
		olderId = getIntent().getStringExtra("olderId");
		authorization = (String) SPUtils.get(this, "authorization", "");
		calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		startyear = calendar.get(Calendar.YEAR);
		startmonth = calendar.get(Calendar.MONTH) + 1;
		startday = 1;
		endyear = calendar.get(Calendar.YEAR);
		endmonth = calendar.get(Calendar.MONTH) + 1;
		endday = calendar.get(Calendar.DAY_OF_MONTH);
		sdf = new SimpleDateFormat("MM-dd HH:mm");
		// 请求的初始数据
		startdaytime = startyear + "-" + startmonth + "-" + "1" + " 00:00:00";
		enddaytime = endyear + "-" + endmonth + "-" + endday + " 23:59:59";
		starttimetv.setText("" + startyear + "-" + startmonth + "-" + "01");
		endtimetv.setText("" + endyear + "-" + endmonth + "-" + endday);
		requestData();
	}

	/**
	 * 请求数据
	 * 
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	protected void requestData() {
		// 8个请求
		requestxueya();
		requestxuetang();
		requestwendu();
		requestxintiao();
		requestxinlv();
		requestxindian();
		requestxueyang();
	}

	/**
	 * 选择开始时间
	 * 
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	public void selectstarttime() {
		DatePickerDialog datePickerDialog = new DatePickerDialog(this,
				AlertDialog.THEME_HOLO_LIGHT, new OnDateSetListener() {
					@Override
					public void onDateSet(DatePicker view, int year,
							int monthOfYear, int dayOfMonth) {
						/**
						 * 保存设置的时间
						 */
						startyear = year;
						startmonth = monthOfYear;
						startday = dayOfMonth;
						if (startyear > endyear) {
							startyear = endyear;
						}
						if (startyear == endyear) {
							if (startmonth > endmonth) {
								startmonth = endmonth;
							}
							if (startmonth == endmonth) {
								if (startday > endday) {
									startday = endday;
								}
							}
						}
						// 2017-10-30 10:30:00
						startdaytime = year + "-" + (monthOfYear + 1) + "-"
								+ dayOfMonth + " 00:00:00";
						starttimetv.setText("" + year + "-" + (monthOfYear + 1)
								+ "-" + dayOfMonth);
						// 刷新数据
						requestData();
					}
				}, startyear, startmonth, startday);

		datePickerDialog.setCancelable(true);
		DatePicker dp = datePickerDialog.getDatePicker();
		dp.setMaxDate(calendar.getTimeInMillis());
		datePickerDialog.show();
	}

	/**
	 * 选择结束时间
	 * 
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	public void selectendtime() {
		DatePickerDialog datePickerDialog = new DatePickerDialog(this,
				AlertDialog.THEME_HOLO_LIGHT, new OnDateSetListener() {
					@Override
					public void onDateSet(DatePicker view, int year,
							int monthOfYear, int dayOfMonth) {
						/**
						 * 保存设置的时间
						 */
						endyear = year;
						endmonth = monthOfYear;
						endday = dayOfMonth;
						// 2017-10-30 10:30:00
						enddaytime = year + "-" + (monthOfYear + 1) + "-"
								+ dayOfMonth + " 23:59:59";
						endtimetv.setText("" + year + "-" + (monthOfYear + 1)
								+ "-" + dayOfMonth);
						// 刷新数据
						requestData();
					}
				}, endyear, endmonth, endday);

		datePickerDialog.setCancelable(true);
		DatePicker dp = datePickerDialog.getDatePicker();
		dp.setMaxDate(calendar.getTimeInMillis());
		datePickerDialog.show();
	}

	/**
	 * 点击事件 ClassName: click
	 * 
	 * @Description: TODO
	 * @author fzq
	 * @date 2017-11-4
	 */
	private class click implements OnClickListener {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.nursing_health_starttime_tv:
				selectstarttime();
				break;
			case R.id.nursing_health_endtime_tv:
				selectendtime();
				break;
			case R.id.nursing_health_icon_xueya_iv:
				if (checkPosition != 0) {
					linelist.get(checkPosition).setVisibility(View.GONE);
					linelist.get(0).setVisibility(View.VISIBLE);
					imagelist.get(checkPosition).setImageResource(
							R.drawable.kongbai);
					imagelist.get(0).setImageResource(
							R.drawable.jiankang_fenlei_xuanzhong);
					checkPosition = 0;
				}
				break;
			case R.id.nursing_health_icon_xuetang_iv:
				if (checkPosition != 1) {
					linelist.get(checkPosition).setVisibility(View.GONE);
					linelist.get(1).setVisibility(View.VISIBLE);
					imagelist.get(checkPosition).setImageResource(
							R.drawable.kongbai);
					imagelist.get(1).setImageResource(
							R.drawable.jiankang_fenlei_xuanzhong);
					checkPosition = 1;
				}
				break;
			case R.id.nursing_health_icon_wendu_iv:
				if (checkPosition != 2) {
					linelist.get(checkPosition).setVisibility(View.GONE);
					linelist.get(2).setVisibility(View.VISIBLE);
					imagelist.get(checkPosition).setImageResource(
							R.drawable.kongbai);
					imagelist.get(2).setImageResource(
							R.drawable.jiankang_fenlei_xuanzhong);
					checkPosition = 2;
				}
				break;
			case R.id.nursing_health_icon_xintiao_iv:
				if (checkPosition != 3) {
					linelist.get(checkPosition).setVisibility(View.GONE);
					linelist.get(3).setVisibility(View.VISIBLE);
					imagelist.get(checkPosition).setImageResource(
							R.drawable.kongbai);
					imagelist.get(3).setImageResource(
							R.drawable.jiankang_fenlei_xuanzhong);
					checkPosition = 3;
				}
				break;
			case R.id.nursing_health_icon_xinlv_iv:
				if (checkPosition != 4) {
					linelist.get(checkPosition).setVisibility(View.GONE);
					linelist.get(4).setVisibility(View.VISIBLE);
					imagelist.get(checkPosition).setImageResource(
							R.drawable.kongbai);
					imagelist.get(4).setImageResource(
							R.drawable.jiankang_fenlei_xuanzhong);
					checkPosition = 4;
				}
				break;
			case R.id.nursing_health_icon_xindian_iv:
				if (checkPosition != 5) {
					linelist.get(checkPosition).setVisibility(View.GONE);
					linelist.get(5).setVisibility(View.VISIBLE);
					imagelist.get(checkPosition).setImageResource(
							R.drawable.kongbai);
					imagelist.get(5).setImageResource(
							R.drawable.jiankang_fenlei_xuanzhong);
					checkPosition = 5;
				}
				break;
			case R.id.nursing_health_icon_huxi_iv:
				if (checkPosition != 6) {
					linelist.get(checkPosition).setVisibility(View.GONE);
					linelist.get(6).setVisibility(View.VISIBLE);
					imagelist.get(checkPosition).setImageResource(
							R.drawable.kongbai);
					imagelist.get(6).setImageResource(
							R.drawable.jiankang_fenlei_xuanzhong);
					checkPosition = 6;
				}
				break;
			case R.id.nursing_health_icon_xueyang_iv:
				if (checkPosition != 7) {
					linelist.get(checkPosition).setVisibility(View.GONE);
					linelist.get(7).setVisibility(View.VISIBLE);
					imagelist.get(checkPosition).setImageResource(
							R.drawable.kongbai);
					imagelist.get(7).setImageResource(
							R.drawable.jiankang_fenlei_xuanzhong);
					checkPosition = 7;
				}
				break;
			default:
				break;
			}
		}
	}

	/**
	 * 请求血氧数据 表格显示
	 * 
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	private void requestxueyang() {
		HashMap<String, String> param = new HashMap<String, String>();
		param.put("oldmanId", olderId);
		param.put("startTime", startdaytime);
		param.put("endTime", enddaytime);
		OkHttpTask.newInstance(this).post(param, OkType.form)
				.addHeader("authorization", authorization)
				.enqueue(new IOkTaskCallback() {
					@Override
					public void onSuccess(String result) {
						if (result != null) {
							Gson gson = new Gson();
							devicesearchbloodoxyJsonBean = gson.fromJson(
									result,
									FollowDeviceSearchBloodOxyJsonBean.class);
							if (devicesearchbloodoxyJsonBean != null
									&& devicesearchbloodoxyJsonBean.getData() != null) {
								// 删除表
								controlxueyangData(devicesearchbloodoxyJsonBean
										.getData());
							}
						}
					}
				}).start(UrlBean.SEARCHBLEBOXYGENRELATIONURL);
	}

	/**
	 * 加载数据
	 * 
	 * @Description: TODO
	 * @param @param data
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	protected void controlxueyangData(DeviceSearchBloodOxyDataBean data) {
		xueyangXdate = new ArrayList<String>();
		xueyangscore = new ArrayList<Float>();
		xueyangmPointValues = new ArrayList<PointValue>();
		xueyangmAxisXValues = new ArrayList<AxisValue>();
		xueyangmaxtv.setText("血氧最高值: " + data.getMax() + "%");
		xueyangmintv.setText("血氧最低值: " + data.getMin() + "%");
		xueyangdatalist = data.getBoxvygenList();
		if (xueyangdatalist == null) {
			ToastUtil.showMessage(this, "暂无数据");
			return;
		}
		for (int i = 0; i < xueyangdatalist.size(); i++) {
			Date date = new Date(xueyangdatalist.get(i).getCreateTime());
			xueyangXdate.add(sdf.format(date));
			xueyangscore.add((float) xueyangdatalist.get(i).getBoxygen());
		}
		for (int i = 0; i < xueyangXdate.size(); i++) {
			xueyangmAxisXValues.add(new AxisValue(i).setLabel(xueyangXdate
					.get(i)));
		}
		for (int i = 0; i < xueyangscore.size(); i++) {
			xueyangmPointValues.add(new PointValue(i, xueyangscore.get(i)));
		}
		initxueyangLineChart();// 初始化
	}

	private void initxueyangLineChart() {
		Line line = new Line(xueyangmPointValues);
		line.setColor(Color.WHITE); // 折线的颜色
		List<Line> lines = new ArrayList<Line>();
		line.setShape(ValueShape.CIRCLE);
		line.setCubic(false);// 曲线是否平滑
		line.setStrokeWidth(2);// 线条的粗细，默认是3
		line.setFilled(false);// 是否填充曲线的面积
		line.setHasLabels(true);// 曲线的数据坐标是否加上备注
		// line.setHasLabelsOnlyForSelected(true);//点击数据坐标提示数据（设置了这个line.setHasLabels(true);就无效）
		line.setHasLines(true);// 是否用直线显示。如果为false 则没有曲线只有点显示
		line.setHasPoints(true);// 是否显示圆点 如果为false 则没有原点只有点显示
		lines.add(line);
		LineChartData data = new LineChartData();
		data.setLines(lines);
		// 坐标轴
		Axis axisX = new Axis(); // X轴
		axisX.setHasTiltedLabels(false); // X轴下面坐标轴字体是斜的显示还是直的，true是斜的显示
		axisX.setTextColor(Color.WHITE); // 设置字体颜色
		// axisX.setTextColor(Color.parseColor("#D6D6D9"));//灰色
		// 坐标轴颜色
		axisX.setLineColor(Color.TRANSPARENT);
		// axisX.setName("未来几天的天气"); //表格名称
		axisX.setTextSize(10);// 设置字体大小
		axisX.setMaxLabelChars(7); // 最多几个X轴坐标，意思就是你的缩放让X轴上数据的个数7<=x<=mAxisValues.length
		axisX.setValues(xueyangmAxisXValues); // 填充X轴的坐标名称
		data.setAxisXBottom(axisX); // x 轴在底部
		// data.setAxisXTop(axisX); //x 轴在顶部
		axisX.setHasLines(true); // x 轴分割线

		Axis axisY = new Axis(); // Y轴
		axisY.setName("");// y轴标注
		axisY.setTextSize(11);// 设置字体大小
		data.setAxisYLeft(axisY); // Y轴设置在左边
		axisY.setLineColor(Color.TRANSPARENT);
		axisY.setTextColor(Color.WHITE);
		// data.setAxisYRight(axisY); //y轴设置在右边
		// 设置行为属性，支持缩放、滑动以及平移
		xueyanglinechartview.setInteractive(true);
		// 设置能否缩放
		xueyanglinechartview.setZoomEnabled(true);
		xueyanglinechartview.setZoomType(ZoomType.HORIZONTAL); // 缩放类型，水平
		xueyanglinechartview.setMaxZoom((float) 3);// 缩放比例
		xueyanglinechartview.setLineChartData(data);
		xueyanglinechartview.setVisibility(View.VISIBLE);
		Viewport v = new Viewport(xueyanglinechartview.getMaximumViewport());
		v.left = 0;
		// 设置当前显示多少数据
		v.right = 8;
		xueyanglinechartview.setCurrentViewport(v);
	}

	/**
	 * xindian
	 * 
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	private void requestxindian() {

		Map<String, String> param = new HashMap<String, String>();
		param.put("id", "" + olderId);
		param.put("pageNo", "1");
		param.put("pageSize", "1");
		OkHttpTask.newInstance(this).post(param, OkType.form)
				.addHeader("authorization", authorization)
				.enqueue(new IOkTaskCallback() {
					@Override
					public void onSuccess(String result) {
						if (result != null) {
							Log.e("xindian", "----------***  " + result);
							Gson gson = new Gson();
							ecgdataJsonBean = gson.fromJson(result,
									FollowDeviceSearchEcgJsonBean.class);
							if (ecgdataJsonBean != null
									&& ecgdataJsonBean.getData() != null) {
								controlxindianData(ecgdataJsonBean.getData());
							}
						}
					}
				}).start(UrlBean.SEARCHHISTORYECGRELATIONURL);

	}

	/**
	 * 加载心电数据
	 * 
	 * @Description: TODO
	 * @param @param data
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	protected void controlxindianData(FollowDeviceSearchEcgDataBean data) {
		if (data.getList() != null && data.getList().size() != 0) {
			xindianXdate = new ArrayList<String>();
			xindianscore = new ArrayList<Integer>();
			xindianmPointValues = new ArrayList<PointValue>();
			xindianmAxisXValues = new ArrayList<AxisValue>();
			xindianmaxtv.setText("心电最高值: " + data.getList().get(0).getRrmax());
			xindianmintv.setText("心电最低值: " + data.getList().get(0).getRrmin());
			xindiandatalist = data.getList().get(0).getEcg().split(",");
			for (int i = 0; i < xindiandatalist.length; i++) {
				xindianXdate.add("" + 10 * i);
				try {
					xindianscore.add(Integer.valueOf(xindiandatalist[i]));
				} catch (NumberFormatException e) {
					e.printStackTrace();
				}
			}
			for (int i = 0; i < xindianXdate.size(); i++) {
				xindianmAxisXValues.add(new AxisValue(i).setLabel(xindianXdate
						.get(i)));
			}
			for (int i = 0; i < xindianscore.size(); i++) {
				xindianmPointValues.add(new PointValue(i, xindianscore.get(i)));
			}
			initxindianLineChart();// 初始化
		}
	}

	private void initxindianLineChart() {
		Line line = new Line(xindianmPointValues);
		line.setColor(Color.WHITE); // 折线的颜色
		List<Line> lines = new ArrayList<Line>();
		line.setCubic(false);// 曲线是否平滑
		line.setStrokeWidth(1);// 线条的粗细，默认是3
		line.setFilled(false);// 是否填充曲线的面积
		line.setHasLabels(true);// 曲线的数据坐标是否加上备注
		// line.setHasLabelsOnlyForSelected(true);//点击数据坐标提示数据（设置了这个line.setHasLabels(true);就无效）
		line.setHasLines(true);// 是否用直线显示。如果为false 则没有曲线只有点显示
		line.setHasPoints(false);// 是否显示圆点 如果为false 则没有原点只有点显示
		lines.add(line);
		LineChartData data = new LineChartData();
		data.setLines(lines);

		// 坐标轴
		Axis axisX = new Axis(); // X轴
		axisX.setHasTiltedLabels(false); // X轴下面坐标轴字体是斜的显示还是直的，true是斜的显示
		axisX.setTextColor(Color.WHITE); // 设置字体颜色
		// axisX.setTextColor(Color.parseColor("#D6D6D9"));//灰色
		// 坐标轴颜色
		axisX.setLineColor(Color.TRANSPARENT);
		// axisX.setName("未来几天的天气"); //表格名称
		axisX.setTextSize(10);// 设置字体大小
		axisX.setMaxLabelChars(7); // 最多几个X轴坐标，意思就是你的缩放让X轴上数据的个数7<=x<=mAxisValues.length
		axisX.setValues(xindianmAxisXValues); // 填充X轴的坐标名称
		data.setAxisXBottom(axisX); // x 轴在底部
		// data.setAxisXTop(axisX); //x 轴在顶部
		axisX.setHasLines(true); // x 轴分割线
		Axis axisY = new Axis(); // Y轴
		axisY.setName("");// y轴标注
		axisY.setTextSize(10);// 设置字体大小
		data.setAxisYLeft(axisY); // Y轴设置在左边
		axisY.setLineColor(Color.TRANSPARENT);
		axisY.setTextColor(Color.WHITE);
		// data.setAxisYRight(axisY); //y轴设置在右边
		// 设置行为属性，支持缩放、滑动以及平移
		xindianlinechartview.setInteractive(true);
		// 设置能否缩放
		xindianlinechartview.setZoomEnabled(true);
		xindianlinechartview.setZoomType(ZoomType.HORIZONTAL); // 缩放类型，水平
		xindianlinechartview.setMaxZoom((float) 3);// 缩放比例
		xindianlinechartview.setLineChartData(data);
		xindianlinechartview.setVisibility(View.VISIBLE);
		/**
		 * 注：下面的7，10只是代表一个数字去类比而已
		 * 尼玛搞的老子好辛苦！！！见（http://forum.xda-developers.com/tools
		 * /programming/library-hellocharts-charting-library-t2904456/page2）;
		 * 下面几句可以设置X轴数据的显示个数
		 * （x轴0-7个数据），当数据点个数小于（29）的时候，缩小到极致hellochart默认的是所有显示。当数据点个数大于（29）的时候，
		 * 若不设置axisX.setMaxLabelChars(int count)这句话,则会自动适配X轴所能显示的尽量合适的数据个数。
		 * 若设置axisX.setMaxLabelChars(int count)这句话, 33个数据点测试，若
		 * axisX.setMaxLabelChars(10);里面的10大于v.right= 7; 里面的7，则
		 * 刚开始X轴显示7条数据，然后缩放的时候X轴的个数会保证大于7小于10 若小于v.right=
		 * 7;中的7,反正我感觉是这两句都好像失效了的样子 - -! 并且Y轴是根据数据的大小自动设置Y轴上限 若这儿不设置 v.right= 7;
		 * 这句话，则图表刚开始就会尽可能的显示所有数据，交互性太差
		 */
		Viewport v = new Viewport(xindianlinechartview.getMaximumViewport());
		v.left = 0;
		// 设置当前显示多少数据
		v.right = 100;
		xindianlinechartview.setCurrentViewport(v);
	}

	/**
	 * 请求心率
	 * 
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	private void requestxinlv() {
		Map<String, String> param = new HashMap<String, String>();
		param.put("oldmanId", "" + olderId);
		param.put("startTime", startdaytime);
		param.put("endTime", enddaytime);
		OkHttpTask.newInstance(this).post(param, OkType.form)
				.addHeader("authorization", authorization)
				.enqueue(new IOkTaskCallback() {
					@Override
					public void onSuccess(String result) {
						if (result != null) {
							Log.e("healthdate", "--------" + result);
							Gson gson = new Gson();
							heartrateJsonBean = gson.fromJson(result,
									FollowDeviceSearchHeartRateJsonBean.class);
							if (heartrateJsonBean != null
									&& heartrateJsonBean.getData() != null) {
								controlxinlvData(heartrateJsonBean.getData());
							}
						}
					}
				}).start(UrlBean.SEARCHGEARTRATERELATIONURL);
	}

	protected void controlxinlvData(FollowDeviceSearchHeartRateDataBean data) {
		xinlvXdate = new ArrayList<String>();
		xinlvscore = new ArrayList<Integer>();
		xinlvmPointValues = new ArrayList<PointValue>();
		xinlvmAxisXValues = new ArrayList<AxisValue>();
		xinlvmaxtv.setText("" + data.getMax() + "BPM");
		xinlvmintv.setText("" + data.getMin() + "BPM");
		xinlvdatalist = data.getHeartrateList();
		if (xinlvdatalist == null) {
			ToastUtil.showMessage(this, "暂无数据");
			return;
		}
		for (int i = 0; i < xinlvdatalist.size(); i++) {
			Date date = new Date(xinlvdatalist.get(i).getCreateTime());
			xinlvXdate.add(sdf.format(date));
			xinlvscore.add(xinlvdatalist.get(i).getHeartRate());
		}
		for (int i = 0; i < xinlvXdate.size(); i++) {
			xinlvmAxisXValues.add(new AxisValue(i).setLabel(xinlvXdate.get(i)));
		}
		for (int i = 0; i < xinlvscore.size(); i++) {
			xinlvmPointValues.add(new PointValue(i, xinlvscore.get(i)));
		}
		initxinlvLineChart();// 初始化
	}

	private void initxinlvLineChart() {
		Line line = new Line(xinlvmPointValues);
		line.setColor(Color.WHITE); // 折线的颜色
		List<Line> lines = new ArrayList<Line>();
		line.setShape(ValueShape.CIRCLE);// 折线图上每个数据点的形状 这里是圆形 （有三种
											// ：ValueShape.SQUARE
											// ValueShape.CIRCLE
											// ValueShape.SQUARE）
		line.setCubic(false);// 曲线是否平滑
		line.setStrokeWidth(2);// 线条的粗细，默认是3
		line.setFilled(false);// 是否填充曲线的面积
		line.setHasLabels(true);// 曲线的数据坐标是否加上备注
		// line.setHasLabelsOnlyForSelected(true);//点击数据坐标提示数据（设置了这个line.setHasLabels(true);就无效）
		line.setHasLines(true);// 是否用直线显示。如果为false 则没有曲线只有点显示
		line.setHasPoints(true);// 是否显示圆点 如果为false 则没有原点只有点显示
		lines.add(line);
		LineChartData data = new LineChartData();
		data.setLines(lines);

		// 坐标轴
		Axis axisX = new Axis(); // X轴
		axisX.setHasTiltedLabels(false); // X轴下面坐标轴字体是斜的显示还是直的，true是斜的显示
		axisX.setTextColor(Color.WHITE); // 设置字体颜色
		// axisX.setTextColor(Color.parseColor("#D6D6D9"));//灰色
		// 坐标轴颜色
		axisX.setLineColor(Color.TRANSPARENT);
		// axisX.setName("未来几天的天气"); //表格名称
		axisX.setTextSize(10);// 设置字体大小
		axisX.setMaxLabelChars(7); // 最多几个X轴坐标，意思就是你的缩放让X轴上数据的个数7<=x<=mAxisValues.length
		axisX.setValues(xinlvmAxisXValues); // 填充X轴的坐标名称
		data.setAxisXBottom(axisX); // x 轴在底部
		// data.setAxisXTop(axisX); //x 轴在顶部
		axisX.setHasLines(true); // x 轴分割线
		Axis axisY = new Axis(); // Y轴
		axisY.setName("");// y轴标注
		axisY.setTextSize(11);// 设置字体大小
		data.setAxisYLeft(axisY); // Y轴设置在左边
		axisY.setLineColor(Color.TRANSPARENT);
		axisY.setTextColor(Color.WHITE);
		// data.setAxisYRight(axisY); //y轴设置在右边
		// 设置行为属性，支持缩放、滑动以及平移
		xinlvlinechartview.setInteractive(true);
		// 设置能否缩放
		xinlvlinechartview.setZoomEnabled(true);
		xinlvlinechartview.setZoomType(ZoomType.HORIZONTAL); // 缩放类型，水平
		xinlvlinechartview.setMaxZoom((float) 3);// 缩放比例
		xinlvlinechartview.setLineChartData(data);
		xinlvlinechartview.setVisibility(View.VISIBLE);
		/**
		 * 注：下面的7，10只是代表一个数字去类比而已
		 * 尼玛搞的老子好辛苦！！！见（http://forum.xda-developers.com/tools
		 * /programming/library-hellocharts-charting-library-t2904456/page2）;
		 * 下面几句可以设置X轴数据的显示个数
		 * （x轴0-7个数据），当数据点个数小于（29）的时候，缩小到极致hellochart默认的是所有显示。当数据点个数大于（29）的时候，
		 * 若不设置axisX.setMaxLabelChars(int count)这句话,则会自动适配X轴所能显示的尽量合适的数据个数。
		 * 若设置axisX.setMaxLabelChars(int count)这句话, 33个数据点测试，若
		 * axisX.setMaxLabelChars(10);里面的10大于v.right= 7; 里面的7，则
		 * 刚开始X轴显示7条数据，然后缩放的时候X轴的个数会保证大于7小于10 若小于v.right=
		 * 7;中的7,反正我感觉是这两句都好像失效了的样子 - -! 并且Y轴是根据数据的大小自动设置Y轴上限 若这儿不设置 v.right= 7;
		 * 这句话，则图表刚开始就会尽可能的显示所有数据，交互性太差
		 */
		Viewport v = new Viewport(xinlvlinechartview.getMaximumViewport());
		v.left = 0;
		// 设置当前显示多少数据
		v.right = 8;
		xinlvlinechartview.setCurrentViewport(v);
	}

	/**
	 * 请求心跳
	 * 
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	private void requestxintiao() {
		// 无
		// /Nursing/mettressDevice
		// 请求床垫
		String str = "{\"oldmanId\": " + olderId
				+ ",\"time\": \"\",\"pageNo\": \"1\",\"pageSize\": \"100\"}";
		// 表单提交 这种能满足大部分的需求
		RequestBody requestBody = RequestBody.create(JSON, str);
		client = OkHttpTask.newinstance(this);
		Request request = new Request.Builder()
				.url(UrlBean.DEVICESLEEPDATASEARCHURL)
				.header("authorization", authorization)
				// 表单提交
				.post(requestBody).build();
		client.newBuilder().build().newCall(request).enqueue(new Callback() {
			@Override
			public void onResponse(Call arg0, Response response)
					throws IOException {
				if (response.isSuccessful()) {
					Gson gson = new Gson();
					DeviceSleepDataJsonBean sleepDataJsonBean = gson.fromJson(
							response.body().string(),
							DeviceSleepDataJsonBean.class);
					if (sleepDataJsonBean != null
							&& sleepDataJsonBean.getData() != null) {
						controlSleepData(sleepDataJsonBean.getData());
					}
				}
			}

			@Override
			public void onFailure(Call arg0, IOException arg1) {
			}
		});

	}

	/**
	 * 将心跳数据传到主线程
	 * 
	 * @Description: TODO
	 * @param @param data
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-9
	 */
	protected void controlSleepData(DeviceSleepDataDataBean data) {
		thisdata = data;
		if (data.getList() != null) {
			if (data.getList().size() != 0) {
				HealthListActivity.this.runOnUiThread(new Runnable() {
					@Override
					public void run() {
						controlxintiaoDate(thisdata.getList());
						controlhuxiDate(thisdata.getList());
					}
				});
			}
		}
	}

	// 处理心跳数据
	protected void controlxintiaoDate(List<ListBean> list) {
		xintiaoXdate = new ArrayList<String>();
		xintiaoscore = new ArrayList<Integer>();
		xintiaoPointValues = new ArrayList<PointValue>();
		xintiaomAxisXValues = new ArrayList<AxisValue>();
		for (int i = 0; i < list.size(); i++) {
			date = new Date(list.get(i).getCreateTime());
			xintiaoXdate.add(sdf.format(date));
			xintiaoscore.add(list.get(i).getHeartRate());
		}
		getxintiaopoint();// 获取坐标点
		initxintiaoLineChart();// 初始化
	}

	private void getxintiaopoint() {
		for (int i = 0; i < xintiaoXdate.size(); i++) {
			xintiaomAxisXValues.add(new AxisValue(i).setLabel(xintiaoXdate
					.get(i)));
		}
		for (int i = 0; i < xintiaoscore.size(); i++) {
			xintiaoPointValues.add(new PointValue(i, xintiaoscore.get(i)));
		}
	}

	private void initxintiaoLineChart() {
		Line line = new Line(xintiaoPointValues);
		line.setColor(Color.WHITE); // 折线的颜色
		List<Line> lines = new ArrayList<Line>();
		line.setShape(ValueShape.CIRCLE);
		LineChartValueFormatter chartValueFormatter = new SimpleLineChartValueFormatter(
				1);// 显示一位小数
		line.setFormatter(chartValueFormatter);// 显示小数点
		line.setCubic(false);// 曲线是否平滑
		line.setStrokeWidth(2);// 线条的粗细，默认是3
		line.setFilled(false);// 是否填充曲线的面积
		line.setHasLabels(true);// 曲线的数据坐标是否加上备注
		// line.setHasLabelsOnlyForSelected(true);//点击数据坐标提示数据（设置了这个line.setHasLabels(true);就无效）
		line.setHasLines(true);// 是否用直线显示。如果为false 则没有曲线只有点显示
		line.setHasPoints(true);// 是否显示圆点 如果为false 则没有原点只有点显示
		lines.add(line);
		LineChartData data = new LineChartData();
		data.setLines(lines);
		// 坐标轴
		Axis axisX = new Axis(); // X轴
		axisX.setHasTiltedLabels(false); // X轴下面坐标轴字体是斜的显示还是直的，true是斜的显示
		axisX.setTextColor(Color.WHITE); // 设置字体颜色
		// axisX.setTextColor(Color.parseColor("#D6D6D9"));//灰色
		// 坐标轴颜色
		axisX.setLineColor(Color.TRANSPARENT);
		// axisX.setName("未来几天的天气"); //表格名称
		axisX.setTextSize(10);// 设置字体大小
		axisX.setMaxLabelChars(7); // 最多几个X轴坐标，意思就是你的缩放让X轴上数据的个数7<=x<=mAxisValues.length
		axisX.setValues(xintiaomAxisXValues); // 填充X轴的坐标名称
		data.setAxisXBottom(axisX); // x 轴在底部
		// data.setAxisXTop(axisX); //x 轴在顶部
		axisX.setHasLines(true); // x 轴分割线
		Axis axisY = new Axis(); // Y轴
		axisY.setName("");// y轴标注
		axisY.setTextSize(11);// 设置字体大小
		data.setAxisYLeft(axisY); // Y轴设置在左边
		axisY.setLineColor(Color.TRANSPARENT);
		axisY.setTextColor(Color.WHITE);
		// data.setAxisYRight(axisY); //y轴设置在右边
		// 设置行为属性，支持缩放、滑动以及平移
		xintiaolinechartview.setInteractive(true);
		// 设置能否缩放
		xintiaolinechartview.setZoomEnabled(true);
		xintiaolinechartview.setZoomType(ZoomType.HORIZONTAL); // 缩放类型，水平
		xintiaolinechartview.setMaxZoom((float) 3);// 缩放比例
		xintiaolinechartview.setLineChartData(data);
		xintiaolinechartview.setVisibility(View.VISIBLE);
		/**
		 * 注：下面的7，10只是代表一个数字去类比而已
		 * 尼玛搞的老子好辛苦！！！见（http://forum.xda-developers.com/tools
		 * /programming/library-hellocharts-charting-library-t2904456/page2）;
		 * 下面几句可以设置X轴数据的显示个数
		 * （x轴0-7个数据），当数据点个数小于（29）的时候，缩小到极致hellochart默认的是所有显示。当数据点个数大于（29）的时候，
		 * 若不设置axisX.setMaxLabelChars(int count)这句话,则会自动适配X轴所能显示的尽量合适的数据个数。
		 * 若设置axisX.setMaxLabelChars(int count)这句话, 33个数据点测试，若
		 * axisX.setMaxLabelChars(10);里面的10大于v.right= 7; 里面的7，则
		 * 刚开始X轴显示7条数据，然后缩放的时候X轴的个数会保证大于7小于10 若小于v.right=
		 * 7;中的7,反正我感觉是这两句都好像失效了的样子 - -! 并且Y轴是根据数据的大小自动设置Y轴上限 若这儿不设置 v.right= 7;
		 * 这句话，则图表刚开始就会尽可能的显示所有数据，交互性太差
		 */
		Viewport v = new Viewport(xintiaolinechartview.getMaximumViewport());
		v.left = 0;
		// 设置当前显示多少数据
		v.right = 8;
		xintiaolinechartview.setCurrentViewport(v);

	}

	// 呼吸
	protected void controlhuxiDate(List<ListBean> list) {
		huxiXdate = new ArrayList<String>();
		huxiscore = new ArrayList<Integer>();
		huxiPointValues = new ArrayList<PointValue>();
		huximAxisXValues = new ArrayList<AxisValue>();
		for (int i = 0; i < list.size(); i++) {
			date = new Date(list.get(i).getCreateTime());
			huxiXdate.add(sdf.format(date));
			huxiscore.add(list.get(i).getBreathe());
		}
		gethuxipoint();// 获取坐标点
		inithuxiLineChart();// 初始化
	}

	private void gethuxipoint() {
		for (int i = 0; i < huxiXdate.size(); i++) {
			huximAxisXValues.add(new AxisValue(i).setLabel(huxiXdate.get(i)));
		}
		for (int i = 0; i < huxiscore.size(); i++) {
			huxiPointValues.add(new PointValue(i, huxiscore.get(i)));
		}
	}

	private void inithuxiLineChart() {
		Line line = new Line(huxiPointValues);
		line.setColor(Color.WHITE); // 折线的颜色
		List<Line> lines = new ArrayList<Line>();
		line.setShape(ValueShape.CIRCLE);
		LineChartValueFormatter chartValueFormatter = new SimpleLineChartValueFormatter(
				1);// 显示一位小数
		line.setFormatter(chartValueFormatter);// 显示小数点
		line.setCubic(false);// 曲线是否平滑
		line.setStrokeWidth(2);// 线条的粗细，默认是3
		line.setFilled(false);// 是否填充曲线的面积
		line.setHasLabels(true);// 曲线的数据坐标是否加上备注
		// line.setHasLabelsOnlyForSelected(true);//点击数据坐标提示数据（设置了这个line.setHasLabels(true);就无效）
		line.setHasLines(true);// 是否用直线显示。如果为false 则没有曲线只有点显示
		line.setHasPoints(true);// 是否显示圆点 如果为false 则没有原点只有点显示
		lines.add(line);
		LineChartData data = new LineChartData();
		data.setLines(lines);
		// 坐标轴
		Axis axisX = new Axis(); // X轴
		axisX.setHasTiltedLabels(false); // X轴下面坐标轴字体是斜的显示还是直的，true是斜的显示
		axisX.setTextColor(Color.WHITE); // 设置字体颜色
		// axisX.setTextColor(Color.parseColor("#D6D6D9"));//灰色
		// 坐标轴颜色
		axisX.setLineColor(Color.TRANSPARENT);
		// axisX.setName("未来几天的天气"); //表格名称
		axisX.setTextSize(10);// 设置字体大小
		axisX.setMaxLabelChars(7); // 最多几个X轴坐标，意思就是你的缩放让X轴上数据的个数7<=x<=mAxisValues.length
		axisX.setValues(huximAxisXValues); // 填充X轴的坐标名称
		data.setAxisXBottom(axisX); // x 轴在底部
		// data.setAxisXTop(axisX); //x 轴在顶部
		axisX.setHasLines(true); // x 轴分割线
		Axis axisY = new Axis(); // Y轴
		axisY.setName("");// y轴标注
		axisY.setTextSize(11);// 设置字体大小
		data.setAxisYLeft(axisY); // Y轴设置在左边
		axisY.setLineColor(Color.TRANSPARENT);
		axisY.setTextColor(Color.WHITE);
		// data.setAxisYRight(axisY); //y轴设置在右边
		// 设置行为属性，支持缩放、滑动以及平移
		huxilinechartview.setInteractive(true);
		// 设置能否缩放
		huxilinechartview.setZoomEnabled(true);
		huxilinechartview.setZoomType(ZoomType.HORIZONTAL); // 缩放类型，水平
		huxilinechartview.setMaxZoom((float) 3);// 缩放比例
		huxilinechartview.setLineChartData(data);
		huxilinechartview.setVisibility(View.VISIBLE);
		/**
		 * 注：下面的7，10只是代表一个数字去类比而已
		 * 尼玛搞的老子好辛苦！！！见（http://forum.xda-developers.com/tools
		 * /programming/library-hellocharts-charting-library-t2904456/page2）;
		 * 下面几句可以设置X轴数据的显示个数
		 * （x轴0-7个数据），当数据点个数小于（29）的时候，缩小到极致hellochart默认的是所有显示。当数据点个数大于（29）的时候，
		 * 若不设置axisX.setMaxLabelChars(int count)这句话,则会自动适配X轴所能显示的尽量合适的数据个数。
		 * 若设置axisX.setMaxLabelChars(int count)这句话, 33个数据点测试，若
		 * axisX.setMaxLabelChars(10);里面的10大于v.right= 7; 里面的7，则
		 * 刚开始X轴显示7条数据，然后缩放的时候X轴的个数会保证大于7小于10 若小于v.right=
		 * 7;中的7,反正我感觉是这两句都好像失效了的样子 - -! 并且Y轴是根据数据的大小自动设置Y轴上限 若这儿不设置 v.right= 7;
		 * 这句话，则图表刚开始就会尽可能的显示所有数据，交互性太差
		 */
		Viewport v = new Viewport(huxilinechartview.getMaximumViewport());
		v.left = 0;
		// 设置当前显示多少数据
		v.right = 8;
		huxilinechartview.setCurrentViewport(v);

	}

	/**
	 * 请求温度数据
	 * 
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	private void requestwendu() {
		Map<String, String> param = new HashMap<String, String>();
		param.put("oldmanId", "" + olderId);
		param.put("startTime", startdaytime);
		param.put("endTime", enddaytime);
		OkHttpTask.newInstance(this).post(param, OkType.form)
				.addHeader("authorization", authorization)
				.enqueue(new IOkTaskCallback() {
					@Override
					public void onSuccess(String result) {
						if (result != null) {
							Gson gson = new Gson();
							temperatureJsonBean = gson
									.fromJson(
											result,
											FollowDeviceSearchTemperatureJsonBean.class);
							if (temperatureJsonBean != null
									&& temperatureJsonBean.getData() != null) {
								controlwenduData(temperatureJsonBean.getData());
							}
						}
					}
				}).start(UrlBean.SEARCHTEMPERATURERELATIONURL);
	}

	/**
	 * 加载温度数据
	 * 
	 * @Description: TODO
	 * @param @param data
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	protected void controlwenduData(FollowDeviceSearchTemperatureDataBean data) {
		// 清除数据
		wenduXdate = new ArrayList<String>();
		wenduscore = new ArrayList<Float>();
		wendumPointValues = new ArrayList<PointValue>();
		wendumAxisXValues = new ArrayList<AxisValue>();
		wendumaxtv.setText("温度最高值: " + data.getMax() + "℃");
		wendumintv.setText("温度最低值: " + data.getMin() + "℃");
		wendudatalist = data.getTemperatureList();
		if (wendudatalist == null) {
			ToastUtil.showMessage(this, "暂无数据");
			return;
		}
		for (int i = 0; i < wendudatalist.size(); i++) {
			date = new Date(wendudatalist.get(i).getCreateTime());
			wenduXdate.add(sdf.format(date));
			wenduscore.add(wendudatalist.get(i).getTemperature());
		}

		getwendupoint();// 获取坐标点
		initwenduLineChart();// 初始化
	}

	private void getwendupoint() {
		for (int i = 0; i < wenduXdate.size(); i++) {
			wendumAxisXValues.add(new AxisValue(i).setLabel(wenduXdate.get(i)));
		}
		for (int i = 0; i < wenduscore.size(); i++) {
			wendumPointValues.add(new PointValue(i, wenduscore.get(i)));
		}
	}

	/**
	 * 初始话温度的线
	 * 
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	private void initwenduLineChart() {
		Line line = new Line(wendumPointValues);
		line.setColor(Color.WHITE); // 折线的颜色
		List<Line> lines = new ArrayList<Line>();
		line.setShape(ValueShape.CIRCLE);
		LineChartValueFormatter chartValueFormatter = new SimpleLineChartValueFormatter(
				1);// 显示一位小数
		line.setFormatter(chartValueFormatter);// 显示小数点
		line.setCubic(false);// 曲线是否平滑
		line.setStrokeWidth(2);// 线条的粗细，默认是3
		line.setFilled(false);// 是否填充曲线的面积
		line.setHasLabels(true);// 曲线的数据坐标是否加上备注
		// line.setHasLabelsOnlyForSelected(true);//点击数据坐标提示数据（设置了这个line.setHasLabels(true);就无效）
		line.setHasLines(true);// 是否用直线显示。如果为false 则没有曲线只有点显示
		line.setHasPoints(true);// 是否显示圆点 如果为false 则没有原点只有点显示
		lines.add(line);
		LineChartData data = new LineChartData();
		data.setLines(lines);
		// 坐标轴
		Axis axisX = new Axis(); // X轴
		axisX.setHasTiltedLabels(false); // X轴下面坐标轴字体是斜的显示还是直的，true是斜的显示
		axisX.setTextColor(Color.WHITE); // 设置字体颜色
		// axisX.setTextColor(Color.parseColor("#D6D6D9"));//灰色
		// 坐标轴颜色
		axisX.setLineColor(Color.TRANSPARENT);
		// axisX.setName("未来几天的天气"); //表格名称
		axisX.setTextSize(10);// 设置字体大小
		axisX.setMaxLabelChars(7); // 最多几个X轴坐标，意思就是你的缩放让X轴上数据的个数7<=x<=mAxisValues.length
		axisX.setValues(wendumAxisXValues); // 填充X轴的坐标名称
		data.setAxisXBottom(axisX); // x 轴在底部
		// data.setAxisXTop(axisX); //x 轴在顶部
		axisX.setHasLines(true); // x 轴分割线
		Axis axisY = new Axis(); // Y轴
		axisY.setName("");// y轴标注
		axisY.setTextSize(11);// 设置字体大小
		data.setAxisYLeft(axisY); // Y轴设置在左边
		axisY.setLineColor(Color.TRANSPARENT);
		axisY.setTextColor(Color.WHITE);
		// data.setAxisYRight(axisY); //y轴设置在右边
		// 设置行为属性，支持缩放、滑动以及平移
		wendulinechartview.setInteractive(true);
		// 设置能否缩放
		wendulinechartview.setZoomEnabled(true);
		wendulinechartview.setZoomType(ZoomType.HORIZONTAL); // 缩放类型，水平
		wendulinechartview.setMaxZoom((float) 3);// 缩放比例
		wendulinechartview.setLineChartData(data);
		wendulinechartview.setVisibility(View.VISIBLE);
		/**
		 * 注：下面的7，10只是代表一个数字去类比而已
		 * 尼玛搞的老子好辛苦！！！见（http://forum.xda-developers.com/tools
		 * /programming/library-hellocharts-charting-library-t2904456/page2）;
		 * 下面几句可以设置X轴数据的显示个数
		 * （x轴0-7个数据），当数据点个数小于（29）的时候，缩小到极致hellochart默认的是所有显示。当数据点个数大于（29）的时候，
		 * 若不设置axisX.setMaxLabelChars(int count)这句话,则会自动适配X轴所能显示的尽量合适的数据个数。
		 * 若设置axisX.setMaxLabelChars(int count)这句话, 33个数据点测试，若
		 * axisX.setMaxLabelChars(10);里面的10大于v.right= 7; 里面的7，则
		 * 刚开始X轴显示7条数据，然后缩放的时候X轴的个数会保证大于7小于10 若小于v.right=
		 * 7;中的7,反正我感觉是这两句都好像失效了的样子 - -! 并且Y轴是根据数据的大小自动设置Y轴上限 若这儿不设置 v.right= 7;
		 * 这句话，则图表刚开始就会尽可能的显示所有数据，交互性太差
		 */
		Viewport v = new Viewport(wendulinechartview.getMaximumViewport());
		v.left = 0;
		// 设置当前显示多少数据
		v.right = 8;
		wendulinechartview.setCurrentViewport(v);
	}

	/**
	 * 请求血糖数据
	 * 
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	private void requestxuetang() {
		// 无
	}

	/**
	 * 请求血压数据
	 * 
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	private void requestxueya() {
		/**
		 * 获取血压数据
		 */
		HashMap<String, String> param = new HashMap<String, String>();
		param.put("oldmanId", olderId);
		param.put("startTime", startdaytime);
		param.put("endTime", enddaytime);
		OkHttpTask.newInstance(this).addHeader("authorization", authorization)
				.post(param, OkType.form).enqueue(new IOkTaskCallback() {
					@Override
					public void onSuccess(String result) {
						Gson gson = new Gson();
						if (result != null) {
							searchBloodPressJsonBean = gson.fromJson(result,
									FollowDeviceSearchBloodPressJsonBean.class);
							if (searchBloodPressJsonBean != null) {
								if (searchBloodPressJsonBean.getData() != null) {
									// 删除表
									showxueyaDate(searchBloodPressJsonBean
											.getData());
								}
							}
						}
					}
				}).start(UrlBean.SEARCHBPRESSRELATIONURL);
	}

	/**
	 * 血压数据加载
	 * 
	 * @Description: TODO
	 * @param @param data
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	protected void showxueyaDate(FollowDeviceSearchBloodPressDataBean data) {
		// 清除数据
		xueyaXdate = new ArrayList<String>();
		xueyascore = new ArrayList<Integer>();
		xueyascore2 = new ArrayList<Integer>();
		xueyamPointValues = new ArrayList<PointValue>();
		xueyamPoint2Values = new ArrayList<PointValue>();
		xueyamAxisXValues = new ArrayList<AxisValue>();

		xueyamaxtv.setText("舒张压最大值: " + data.getMAX() + "mmHg");
		xueyamintv.setText("收缩压最小值: " + data.getMIN() + "mmHg");
		xueyadatalist = data.getBpressureList();
		if (xueyadatalist == null) {
			ToastUtil.showMessage(this, "暂无数据");
			return;
		}
		for (int i = 0; i < xueyadatalist.size(); i++) {
			date = new Date(xueyadatalist.get(i).getCreateTime());
			xueyaXdate.add(sdf.format(date));
			xueyascore.add(xueyadatalist.get(i).getDbp());
			xueyascore2.add(xueyadatalist.get(i).getSbp());
		}

		getxueypoint();// 获取坐标点
		initxueyaLineChart();// 初始化
		addxueyaLinetwo();// 添加另一条线
	}

	/**
	 * // 获取坐标点
	 * 
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-11-4
	 */
	private void getxueypoint() {
		for (int i = 0; i < xueyaXdate.size(); i++) {
			xueyamAxisXValues.add(new AxisValue(i).setLabel(xueyaXdate.get(i)));
		}
		for (int i = 0; i < xueyascore.size(); i++) {
			xueyamPointValues.add(new PointValue(i, xueyascore.get(i)));
		}
		for (int i = 0; i < xueyascore2.size(); i++) {
			xueyamPoint2Values.add(new PointValue(i, xueyascore2.get(i)));
		}
	}

	private void initxueyaLineChart() {
		xueyaline = new Line(xueyamPointValues);
		xueyaline.setColor(Color.WHITE); // 折线的颜色
		xueyalines = new ArrayList<Line>();
		xueyaline.setShape(ValueShape.CIRCLE);
		xueyaline.setCubic(false);// 曲线是否平滑
		xueyaline.setStrokeWidth(2);// 线条的粗细，默认是3
		xueyaline.setFilled(false);// 是否填充曲线的面积
		xueyaline.setHasLabels(true);// 曲线的数据坐标是否加上备注
		// line.setHasLabelsOnlyForSelected(true);//点击数据坐标提示数据（设置了这个line.setHasLabels(true);就无效）
		xueyaline.setHasLines(true);// 是否用直线显示。如果为false 则没有曲线只有点显示
		xueyaline.setHasPoints(true);// 是否显示圆点 如果为false 则没有原点只有点显示
		xueyalines.add(xueyaline);
		xueyadata = new LineChartData();
		xueyadata.setLines(xueyalines);
		// 坐标轴
		xueyaaxisX = new Axis(); // X轴
		xueyaaxisX.setHasTiltedLabels(false); // X轴下面坐标轴字体是斜的显示还是直的，true是斜的显示
		xueyaaxisX.setTextColor(Color.WHITE); // 设置字体颜色
		// axisX.setTextColor(Color.parseColor("#D6D6D9"));//灰色
		// 坐标轴颜色
		xueyaaxisX.setLineColor(Color.TRANSPARENT);
		// axisX.setName("未来几天的天气"); //表格名称
		xueyaaxisX.setTextSize(10);// 设置字体大小
		xueyaaxisX.setMaxLabelChars(7); // 最多几个X轴坐标，意思就是你的缩放让X轴上数据的个数7<=x<=mAxisValues.length
		xueyaaxisX.setValues(xueyamAxisXValues); // 填充X轴的坐标名称
		xueyadata.setAxisXBottom(xueyaaxisX); // x 轴在底部
		// data.setAxisXTop(axisX); //x 轴在顶部
		xueyaaxisX.setHasLines(true); // x 轴分割线
		xueyaaxisY = new Axis(); // Y轴
		xueyaaxisY.setName("");// y轴标注
		xueyaaxisY.setTextSize(11);// 设置字体大小
		xueyadata.setAxisYLeft(xueyaaxisY); // Y轴设置在左边
		xueyaaxisY.setLineColor(Color.TRANSPARENT);
		xueyaaxisY.setTextColor(Color.WHITE);
		// data.setAxisYRight(axisY); //y轴设置在右边
		// 设置行为属性，支持缩放、滑动以及平移
		xueyalinechartview.setInteractive(true);
		// 设置能否缩放
		xueyalinechartview.setZoomEnabled(true);
		xueyalinechartview.setZoomType(ZoomType.HORIZONTAL); // 缩放类型，水平
		xueyalinechartview.setMaxZoom((float) 3);// 缩放比例
		xueyalinechartview.setLineChartData(xueyadata);
		xueyalinechartview.setVisibility(View.VISIBLE);
		Viewport v = new Viewport(xueyalinechartview.getMaximumViewport());
		v.left = 0;
		// 设置当前显示多少数据
		v.right = 8;
		xueyalinechartview.setCurrentViewport(v);
	}

	private void addxueyaLinetwo() {
		xueyaline2 = new Line(xueyamPoint2Values);
		xueyaline2.setColor(Color.WHITE); // 折线的颜色
		xueyaline2.setShape(ValueShape.CIRCLE);
		xueyaline2.setCubic(false);// 曲线是否平滑
		xueyaline2.setStrokeWidth(2);// 线条的粗细，默认是3
		xueyaline2.setFilled(false);// 是否填充曲线的面积
		xueyaline2.setHasLabels(true);// 曲线的数据坐标是否加上备注
		xueyaline2.setHasLines(true);// 是否用直线显示。如果为false 则没有曲线只有点显示
		xueyaline2.setHasPoints(true);// 是否显示圆点 如果为false 则没有原点只有点显示
		xueyalines.add(xueyaline2);
		xueyadata2 = new LineChartData();
		xueyadata2.setLines(xueyalines);
		xueyadata2.setAxisXBottom(xueyaaxisX); // x 轴在底部
		xueyadata2.setAxisYLeft(xueyaaxisY); // Y轴设置在左边
		xueyadata2.setBaseValue(Float.NEGATIVE_INFINITY);
		xueyalinechartview.setLineChartData(xueyadata2);
	}

}
